<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="stylesheet" href="assets/css/amazeui.min.css"/>
    <link rel="stylesheet" href="assets/css/base.css">
    <link rel="stylesheet" type="text/css" href="assets/css/swiper.3.2.0.min.css">
    <link rel="stylesheet" type="text/css" href="assets/css/app.css">
</head>
<body class="am-with-fixed-header">
<header class="am-header am-header-default am-header-fixed am-no-layout" data-am-widget="header">
    <div class="am-header-left am-header-nav">
        <a href="javascript:void(0);" onClick="javascript:history.back(-1);">
            <i class="at-icon at-icon-arrow-left"></i>
        </a>
    </div>
    <h1 class="am-header-title">
        预约看房
    </h1>
</header>
<div class="am-g">
    <form class="am-form loginpage" id="appointmentForm">
        <div class="am-form-group">
            <input type="tel" id="phonenumber" name="phonenumber" placeholder="手机号码">
        </div>
        <div class="am-form-group">
            <input type="number" id="vdcode" name="vdcode" placeholder="验证码" style="width: 68%;" class="am-fl">
            <a href="javascript:void(0);" class="am-btn am-btn-default am-btn-primary am-fr font90 getCode"
               style="width: 30%; padding: 1rem 1rem">获取验证码</a>

            <div class="clearfix"></div>
        </div>
        <div class="am-form-group">
            <a href="javascript:void(0);" class="am-btn am-btn-default am-btn-primary am-btn-block confirmBtn">确定</a>
        </div>
    </form>
</div>
<div class="successBox">
    <h2>预约已提交成功</h2>

    <p>看房顾问会电话和你确认信息</p>
</div>
<script src="assets/js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="assets/js/amazeui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="assets/js/swiper.3.2.0.min.js" type="text/javascript" charset="utf-8"></script>
<script src="assets/js/haoban/app.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
    var InterValObj; //timer变量，控制时间
    var curCount = 0;//当前剩余秒数
    function request(paramName) {
        //获取URL的字符串
        var sSource = String(window.document.location);
        var sName = paramName;
        var sReturn = "";
        var sQUS = "?";
        var sAMP = "&";
        var sEQ = "=";
        var iPos;

        //获取sSource中的"?"，无则返回 -1
        iPos = sSource.indexOf(sQUS);
        if (iPos == -1)
            return;

        //汲取参数，从iPos letters 置到sSource.length-iPos的 letters 置，
        //若iPos = -1，则：从-1 到 sSource.length+1
        var strQuery = sSource.substr(iPos, sSource.length - iPos);

        // alert(strQuery);
        //先全部转换为小写
        var strLCQuery = strQuery.toLowerCase();
        var strLCName = sName.toLowerCase();

        //从子字符串strLCQuery中查找“?”、参数名，以及“=”，即“?参数名=”
        iPos = strLCQuery.indexOf(sQUS + strLCName + sEQ);
        //alert(iPos);
        //如果不存在
        if (iPos == -1) {
            //继续查找可能的后一个参数，即带“&参数名=”
            iPos = strLCQuery.indexOf(sAMP + strLCName + sEQ);
        }

        //判断是否存在参数
        if (iPos != -1) {
            sReturn = strQuery.substr(iPos + sName.length + 2, strQuery.length - (iPos + sName.length + 2));
            var iPosAMP = sReturn.indexOf(sAMP);
            if (iPosAMP == -1) {
                return sReturn;
            }
            else {
                sReturn = sReturn.substr(0, iPosAMP);
            }
        }
        return sReturn;
    }

    $(".getCode").on("click", function () {
        if ($.trim($("input[name='phonenumber']").val()) == "" || $("input[name='phonenumber']").val() == null) {
            alert("请填写手机号！");
            return false;
        } else {
            getPhoneCode();
        }
    });
    $(".confirmBtn").on("click", function () {
        if ($.trim($("input[name='phonenumber']").val()) == "" || $("input[name='phonenumber']").val() == null) {
            alert("请填写手机号！");
            return false;
        }
        if ($.trim($("input[name='vdcode']").val()) == "" || $("input[name='phonenumber']").val() == null) {
            alert("请填写验证码！");
            return false;
        }
        appointHouseSource();

    });
    function getPhoneCode() {
        if (curCount == 0) {
            var count = 60; //间隔函数，1秒执行
            curCount = count;//设置button效果，开始计时
            $(".getCode").attr("disabled", "true");
            $(".getCode").html(curCount + "秒");
            InterValObj = window.setInterval(SetRemainTimeRegister, 1000); //启动计时器，1秒执行一次
            $.ajax({
                method: 'POST',
                url: ctx + "/anonymous/register",
                data: {
                    telephone: $('#phonenumber').val()
                },
                async: false,
                success: function (response) {
                    alert("验证码发送成功")
                }
            });

        }
    }

    function SetRemainTimeRegister() {
        if (curCount == 0) {
            window.clearInterval(InterValObj);//停止计时器
            $(".getCode").removeAttr("disabled");//启用按钮
            $(".getCode").html("重发");
        }
        else {
            curCount--;
            $(".getCode").html(curCount + "秒");
        }
    }

    function appointHouseSource() {
        $.ajax({
            method: 'POST',
            url: ctx + "/anonymous/appointHouseSource",
            data: {
                telephone: $('#phonenumber').val(),
                vcode: $('#vdcode').val(),
                houseSourceId: request('houseSourceId'),
                buildingId: request('buildingId'),
                source: 'share'
            },
            async: false,
            success: function (response) {
                $(".successBox").show(function () {
                    $('#phonenumber').val("");
                    $('#vdcode').val("");
                    setTimeout("$('.successBox').hide()", 3000);
//                    setTimeout("$('#appointmentForm').submit()",3000);
                })
//                alert("预约成功")
            }
        });

    }

</script>
</body>
</html>